package com.tofindaway.hibernate.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

@Repository
public class AbstractDaoImp {

	private SessionFactory sessionFactory;

	public void init() throws Exception {
		Assert.state(getSessionFactory() != null, "sessionFactory not defined");
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public Session getSession() {
		return getSessionFactory().getCurrentSession();
	}

}
